<template>
  <div class="contents">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="智能定价" name="first">
        <el-row align="left" :gutter="10" type="flex">
          <el-col :span="8">
            <span>发货日期：</span>
            <el-date-picker placeholder="选择日期" type="date" />
          </el-col>
          <el-col :span="6">
            <el-select v-model="stores" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-col>
        </el-row>
        <div class="formTitle">
          <span>待定价商品清单</span>
          <span class="subTitle">
            （如需要针对指定客户订单进行核准价，请在批量核算或者订单核算改价）
          </span>
        </div>
        <el-row v-if="selects" align="middle" :gutter="10" type="flex">
          <el-col :span="5">
            <el-cascader :options="options" />
          </el-col>
          <el-col :span="7">
            <el-input placeholder="输入商品名称/编码查询">
              <el-button slot="append" icon="el-icon-search" />
            </el-input>
          </el-col>
          <el-col :span="8">
            <el-checkbox v-model="onlyShow">只显示已下单商品</el-checkbox>
          </el-col>
          <el-col :span="6">
            <el-button>同步订单价格</el-button>
            <el-button>同步商品图片</el-button>
          </el-col>
        </el-row>
        <el-row v-else align="middle" :gutter="15" type="flex">
          <el-col :span="12">
            <span style="color: rgb(60, 195, 71); font-size: 12px;">
              批量设置定价公式，可以对下方勾选的所有商品设置公式； 已勾选
              <b style="color: rgb(223, 80, 0);">{{ selectnum }}</b>
              个商品
            </span>
          </el-col>
          <el-col :span="15">
            <el-button size="mini">清除公式</el-button>
            <el-button size="mini">同步选中商品订单价格</el-button>
            <el-button size="mini">同步选中商品档案价格</el-button>
            <el-button size="mini" type="success" @click="Batchsetting = true">
              批量设置定价公式
            </el-button>
          </el-col>
        </el-row>
        <el-dialog
          title="批量设置定价公式"
          :visible.sync="Batchsetting"
          width="520px"
        >
          <el-row :gutter="10" type="flex" align="middle" class="form-rows">
            <el-col :span="4">
              客户类型：
            </el-col>
            <el-col :span="20">
              <el-select
                v-model="value"
                placeholder="请选择"
                @change="selectMode"
                style="width: 100%;"
              >
                <el-option
                  v-for="item in formula"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-col>
          </el-row>
          <el-row
            :gutter="10"
            type="flex"
            align="middle"
            style="margin-top: 10px;"
          >
            <el-col :span="4">
              计算方式：
            </el-col>
            <el-col :span="20">
              <el-select
                v-model="value"
                placeholder="请选择"
                @change="selectMode"
                style="width: 100%;"
              >
                <el-option
                  v-for="item in formula"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-col>
          </el-row>
          <el-row align="middle" type="flex" style="margin-top: 10px;">
            <el-col :span="24">
              <span>销售价 = </span>
              <el-input style="display: inline-block; width: 150px;" />
            </el-col>
          </el-row>
          <span slot="footer" class="dialog-footer">
            <el-button @click="Batchsetting = false">取 消</el-button>
            <el-button @click="Batchsetting = false">保存并退出</el-button>
            <el-button type="primary" @click="Batchsetting = false">
              保存并继续设置
            </el-button>
          </span>
        </el-dialog>
        <el-table
          ref="multipleTable"
          :data="tableData"
          style="width: 100%; margin-top: 10px;"
          tooltip-effect="dark"
          @selection-change="handleSelectionChange"
        >
          <el-table-column align="center" type="selection" width="55" />
          <el-table-column
            label="商品名称"
            prop="name"
            show-overflow-tooltip
            width="120"
          />
          <el-table-column label="商品编码" prop="code" width="120" />
          <el-table-column
            label="单位"
            prop="unit"
            show-overflow-tooltip
            width="60"
          />
          <el-table-column label="是否已下单" width="120" />
          <el-table-column label="同步订单价" width="120" />
          <el-table-column label="同步商品价" width="120" />
          <el-table-column label="上次定价时进价" width="120" />
          <el-table-column label="最后一次进价" width="120" />
          <el-table-column label="客户类型价" width="120" />
          <el-table-column label="操作" width="120">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="success"
                @click="handleEdit(scope.$index, scope.row)"
              >
                设置公式
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-drawer
          custom-class="drawerSty"
          :modal="false"
          :show-close="false"
          :title="drawerTitle"
          :visible.sync="drawer"
        >
          <el-card
            :body-style="{ padding: '16px' }"
            class="box-card"
            shadow="never"
          >
            <el-row
              align="middle"
              class="form-rows"
              :gutter="10"
              style="padding-top: 0;"
              type="flex"
            >
              <el-col :span="12">
                <span>计算方式：</span>
                <el-select
                  v-model="value"
                  placeholder="请选择"
                  @change="selectMode"
                  style="width: 110px;"
                >
                  <el-option
                    v-for="item in formula"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-col>
              <el-col :span="12" style="text-align: right;">
                默认客户类型*（市场价）
              </el-col>
            </el-row>
            <el-row
              align="middle"
              class="form-rows"
              type="flex"
              v-show="this.showIndex != 0"
            >
              <el-col :span="24">
                <span v-show="this.showIndex == 1">进价 + 加价值</span>
                <span v-show="this.showIndex == 2">进价 + 进价*加价率</span>
                <span v-show="this.showIndex == 3">
                  成本 ÷（1 - 销售加价率）
                </span>
                <el-input style="display: inline-block; width: 100px;" />
                <span>%</span>
                = 销售价
              </el-col>
            </el-row>
            <el-row
              align="middle"
              class="form-rows"
              type="flex"
              v-show="this.showIndex != 0"
            >
              <el-col :span="18">
                <span>计算明细：</span>
                <span>0.00 +</span>
                <span>0 =</span>
                <span>0</span>
              </el-col>
              <el-col :span="6" style="text-align: right;">最近价格: 0</el-col>
            </el-row>
          </el-card>
        </el-drawer>

        <el-pagination
          background
          layout="total, prev, pager, next, sizes, jumper"
          :page-size="10"
          :page-sizes="[10, 20, 30, 40]"
          style="text-align: left;"
          :total="2"
        />
      </el-tab-pane>
      <el-tab-pane label="历史定价" name="second">
        <el-form class="demo-form-inline" :inline="true" :model="historyprice">
          <el-form-item label="发货日期:">
            <el-date-picker
              v-model="historyprice.date"
              end-placeholder="结束日期"
              range-separator="-"
              start-placeholder="开始日期"
              style="width: 200px;"
              type="daterange"
            />
          </el-form-item>
          <el-form-item label="搜索:">
            <el-input
              v-model="historyprice.desc"
              placeholder="请选商品名/助记码/编码/别名/关键字"
            />
          </el-form-item>
          <el-form-item label="搜索:">
            <el-input v-model="historyprice.desc" placeholder="单号/制单人" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary">查询</el-button>
          </el-form-item>
        </el-form>
        <el-table :data="historyData" style="width: 100%; margin-top: 8px;">
          <el-table-column label="定价单号" prop="date" />
          <el-table-column label="定价时间" prop="name" />
          <el-table-column label="发货日期" prop="address" />
          <el-table-column label="制单人" prop="address" />
          <el-table-column label="同步类型" prop="address" />
          <el-table-column label="商品总数" prop="address" />
          <el-table-column label="操作" prop="address" />
        </el-table>
        <el-pagination
          background
          layout="total, prev, pager, next, sizes"
          :page-size="10"
          :page-sizes="[20, 30, 40, 50]"
          style="text-align: right;"
          :total="0"
        />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        activeName: 'first',
        stores: '默认库房',
        options: [
          {
            value: '0',
            label: '默认库房',
          },
          {
            value: '1',
            label: '冻货库房',
          },
        ],
        onlyShow: false,
        selects: true,
        selectnum: 0,
        Batchsetting: false,
        tableData: [{ name: '带皮五花肉 冷鲜', code: 11001, unit: '斤' }],
        drawer: false,
        drawerTitle: '',
        formula: [
          {
            value: '0',
            label: '不设置公式',
          },
          {
            value: '1',
            label: '加价值',
          },
          {
            value: '2',
            label: '成本加价率',
          },
          {
            value: '3',
            label: '销售加价率',
          },
        ],
        value: '不设置公式',
        showIndex: 0,
        historyprice: {},
        historyData: [],
      }
    },
    methods: {
      handleClick(tab, event) {
        console.log(tab, event)
      },
      handleSelectionChange(val) {
        if (val.length > 0) {
          this.selects = false
          val.forEach((item, index) => {
            console.log(item)
            this.selectnum = index + 1
          })
        } else {
          this.selects = true
          this.selectnum = 0
        }
      },
      handleEdit(index, item) {
        this.drawer = true
        this.drawerTitle = `商品：${item.name}(${item.unit})`
        console.log(index)
        console.log(item)
      },
      selectMode(index) {
        console.log(index)
        this.showIndex = index
      },
    },
  }
</script>

<style lang="scss" scoped>
  .contents {
    padding: 0 20px;

    .formTitle {
      font-size: 15px;
      text-align: left;
      margin-bottom: 15px;
      margin-top: 8px;

      .subTitle {
        color: #999;
        font-size: 13px;
      }
    }
  }
</style>
<style lang="scss">
  .drawerSty {
    width: 450px !important;
    .el-drawer__header {
      font-size: 15px;
      background: #f2f2f2;
      padding: 18px;
      margin-bottom: 15px;
      color: #303030;
    }

    .el-drawer__body {
      padding: 20px;
      overflow-y: scroll;
      max-height: 92vh;
      font-size: 13px;
    }

    .form-rows {
      border-bottom: 1px dashed #ddd;
      padding: 18px 0;
    }
  }
</style>
